package command;

import items.Item;
import elements.Robot;
/**
 * A class of basic commands representing the pickup and use operation.
 * 
 * @version	3.0
 * @author 	Lies Tambeur 	r0264469	2Bcwsbbh
 * @author	Eline Vanrykel	r0264543	2Bcwselt
 */
public class PickupAndUse extends BasicCommand {
	/**
	 * The given robot picks up an item if there is an item on the same board and position as the robot and uses it.
	 * @effect	If there is an item on the same board and position as the robot, the robot picks it up and uses it.
	 */
	@Override
	public void execute(Robot robot) {
		if(!robot.getBoard().getItems(robot.getPosition()).isEmpty()){
			Item item = robot.getBoard().getItems(robot.getPosition()).iterator().next();
			robot.pickUp(item);
			robot.use(item);
		}
	}
	@Override
	public String toString(){
		return "(pickup-and-use)";
	}
	
	@Override
	public boolean equals(Object object){
		if(object == null || this==null){
			return false;
		}
		return this.toString().equals(object.toString());
	}

}
